package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.embed.Notify;
import com.moyq5.mvc.maker.test.bean.enums.SysNotifyStatus;

/**
 * 投币记录
 * @author Moyq5
 * @date 2018年4月14日
 */
@Entity
@Table(name = "iot_coin")
@DynamicUpdate
public class IotCoin implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7323882110911645105L;
	/**
	 * 投币ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "coin_id")
	private Long coinId;
	/**
     * 序列号
     */
    @Column(name = "coin_no", nullable = false, length = 32)
    private String coinNo;
	/**
	 * 设备
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "device_id")
	private IotDevice device;
	/**
     * 投币金额
     */
    @Column(name = "amount", nullable = false, precision = 10, scale = 2)
    private BigDecimal amount;
    /**
	 * 投币时间
	 */
	@Column(name = "coin_time", nullable = false, columnDefinition="datetime")
	private Date coinTime;
	/**
	 * 添加时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;

	@Embedded
	private Notify notify;
	
	@PrePersist
	public void prePersist() {
		if (null == addTime) {
			addTime = new Date();
		}
		if (null == notify) {
			notify = new Notify();
		}
		if (null == notify.getNotifyStatus()) {
			notify.setNotifyStatus(SysNotifyStatus.NEW);
		}
		if (null == notify.getNotifyCount()) {
			notify.setNotifyCount(0);
		}
		if (null == notify.getNotifyRemain()) {
			notify.setNotifyRemain(10);
		}
		if (null == notify.getNotifyTime()) {
			notify.setNotifyTime(new Date());
		}
	}
	
	public Long getCoinId() {
		return coinId;
	}
	public void setCoinId(Long coinId) {
		this.coinId = coinId;
	}
	public IotDevice getDevice() {
		return device;
	}
	public void setDevice(IotDevice device) {
		this.device = device;
	}
	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}
	public Date getCoinTime() {
		return coinTime;
	}
	public void setCoinTime(Date coinTime) {
		this.coinTime = coinTime;
	}
	public String getCoinNo() {
		return coinNo;
	}
	public void setCoinNo(String coinNo) {
		this.coinNo = coinNo;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public Notify getNotify() {
		return notify;
	}

	public void setNotify(Notify notify) {
		this.notify = notify;
	}
	
}
